import {getUserInfo, login} from '@/api'
import { defineStore } from 'pinia'
import {ElMessage} from "element-plus";

export let Token = defineStore('saveToken', {
    state: () => ({
        token: '',
        userInfo: {data:{}}
    }),
    getters: {

    },
    actions: {
       async saveToken(data) {
           const res = await login(data)
           this.token = res.token
           ElMessage.success(res.message)
           localStorage.setItem('token',res.token)
       },
       async saveInfo() {
           const { data } = await getUserInfo()
           this.userInfo.data = data
       },
       logout(){
           localStorage.removeItem('token')
           this.token = ''
           this.userInfo.data = {}
       }
    },
})

